import Vue from 'vue'
import axios from 'axios';
import VueAxios from 'vue-axios';
import Qs from 'qs';
import VueCookie from "vue-cookie";

Vue.use(VueAxios, axios);

// 添加请求拦截器
axios.interceptors.request.use(function (config) {
    config.headers['Accept'] = 'application/json';
    const token = VueCookie.get('user_token');
    if(token){
        config.headers['Authorization'] = 'Bearer ' + token;
    }
    return config;
}, function (error) {
    return Promise.reject(error);
});

// 添加响应拦截器
axios.interceptors.response.use(function (response) {
    // 对响应数据做点什么

    return response.data;
}, function (error) {
    // 对响应错误做点什么
    return Promise.reject(error);
});

// 定义基础路由
let base = '/api';

// 大驼峰命名请求方法名称
//登录
export const UserLogin = params => { return axios.post(`${base}/login`, Qs.stringify(params)).then(res => res)};
//分组
export const Group = params => { return axios.get(`${base}/group`, params).then(res => res)};
export const GroupUpdate = params => { return axios.post(`${base}/group/update`, Qs.stringify(params)).then(res => res)};//更新
export const GroupDestroy = params => { return axios.post(`${base}/group/destroy`, Qs.stringify(params)).then(res => res)};//删除
//档案
export const Member = params => { return axios.get(`${base}/member`, params).then(res => res)};
export const MemberInfo = params => { return axios.get(`${base}/member/info`, params).then(res => res)};
export const MemberUpdate = params => { return axios.post(`${base}/member/update`, Qs.stringify(params)).then(res => res)};//更新
export const MemberDestroy = params => { return axios.post(`${base}/member/destroy`, Qs.stringify(params)).then(res => res)};//删除

















































